home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / ClipBoard.C < prev    next >
C/C++ Source or Header  |  1992-07-24  |  2KB  |  98 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "ClipBoard.h"
  6.  
  7. #include "Class.h"
  8. #include "View.h"
  9. #include "MemBuf.h"
  10. #include "WindowSystem.h"
  11. #include "Data.h"
  12. #include "String.h"
  13.  
  14. //---- ClipBoard ---------------------------------------------------------------
  15.  
  16. NewMetaImpl(ClipBoard,Object, (TP(data)));
  17.  
  18. ClipBoard::ClipBoard()
  19. {
  20.     data= 0;
  21. }
  22.  
  23. ClipBoard::~ClipBoard()
  24. {
  25.     SafeDelete(data);
  26. }
  27.  
  28. void ClipBoard::SetData(Data *d)
  29. {
  30.     SafeDelete(data);
  31.     data= d;
  32. }
  33.  
  34. bool ClipBoard::CanPaste(View *v)
  35. {
  36.     gWindowSystem->DevCheckSelection();
  37.     if (v && data)
  38.     return v->CanPaste(data);
  39.     return FALSE;
  40. }
  41.  
  42. void ClipBoard::SelectionToClipboard(Object *op, bool makecopy)
  43. {
  44.     if (makecopy && op)
  45.     op= op->DeepClone();
  46.     if (op) {
  47.     SetData(new ObjectData(op));
  48.     gWindowSystem->DevHaveSelection(data);
  49.     }
  50. }
  51.  
  52. extern bool gPaste;
  53.  
  54. Command *ClipBoard::PasteClipboard(View *v)
  55. {   
  56.     if (v && data) {
  57.     gPaste= TRUE;
  58.     v->PasteData(data);
  59.     gPaste= FALSE;
  60.     return v->PasteData(data);
  61.     }
  62.     return gNoChanges;
  63. }
  64.  
  65. char *ClipBoard::GetExtSelection(int *retlen, Symbol type, Class *want)
  66. {
  67.     char *buf= 0;
  68.     
  69.     *retlen= 0;
  70.     if (data) {
  71.     if (gDebug)
  72.         fprintf(stderr, "ClipBoard::GetExtSelection: %s\n", type.AsString());
  73.     if (want == 0)
  74.         want= Meta(Object);
  75.     Object *op= data->AsObject(want);
  76.  
  77.     if (op) {
  78.         if (type == cDocTypeET) {
  79.         MemBuf *mb= new MemBuf;
  80.         OStream os(mb);
  81.         os << op;
  82.         os.flush();
  83.         mb->SwitchToRead();
  84.         *retlen= (int) mb->ContentsSize();
  85.         buf= mb->Base();
  86.         }
  87.         if (type == cDocTypeAscii) {
  88.         buf= op->AsString();
  89.         if (buf)
  90.             *retlen= strlen(buf);
  91.         }
  92.         SafeDelete(op);
  93.     }
  94.     }
  95.     return buf;
  96. }
  97.  
  98.